//
//  LoginDetailView.m
//  MZSystem
//
//  Created by 智障 on 2018/11/6.
//  Copyright © 2018 zerod. All rights reserved.
//

#import "LoginDetailView.h"

@interface LoginDetailView()<UITextFieldDelegate>

@end
@implementation LoginDetailView

- (IBAction)loginButtonClick:(UIButton *)sender {
    if (self.loginBlock) {
        self.loginBlock();
    }
}

- (IBAction)connectUSClick:(UIButton *)sender {
    NSMutableString * str=[[NSMutableString alloc] initWithFormat:@"tel:%@",@"057185310049"];
    UIWebView * callWebview = [[UIWebView alloc] init];
    [callWebview loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:str]]];
    [self addSubview:callWebview];
}


-(void)awakeFromNib{
    [super awakeFromNib];
    
    
    _loginNameTF.attributedPlaceholder = [self getPlaceHolderTextWith:@"账 号"];
    _loginNameTF.delegate = self;
    NSString *name = [CoreArchive strForKey:LoginName];
    if (name.length > 0) {
        _loginNameTF.text = name;
    }
    
    
    _pswTF.attributedPlaceholder = [self getPlaceHolderTextWith:@"密 码"];
    _pswTF.delegate = self;
    _pswTF.secureTextEntry = YES;
    NSString *psw = [CoreArchive strForKey:LoginPSW];
    if (psw.length > 0) {
        _pswTF.text = psw;
    }
    
    _loginButton.clipsToBounds = YES;
    _loginButton.layer.cornerRadius = 5.f;

}
-(BOOL)textFieldShouldReturn:(UITextField *)textField{
    if (textField == self.loginNameTF) {
        [self.pswTF becomeFirstResponder];
    }
    if (textField == self.pswTF) {
        [self.pswTF resignFirstResponder];
        if (self.loginBlock) {
            self.loginBlock();
        }
    }
    return YES;
}
- (NSMutableAttributedString *)getPlaceHolderTextWith:(NSString *)str{
    NSMutableAttributedString *loginNamePlace_attributedString = [[NSMutableAttributedString alloc] initWithString:str];
    [loginNamePlace_attributedString addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:15.0f] range:NSMakeRange(0, 3)];
    [loginNamePlace_attributedString addAttribute:NSForegroundColorAttributeName value:[UIColor colorWithRed:133.0f/255.0f green:156.0f/255.0f blue:170.0f/255.0f alpha:1.0f] range:NSMakeRange(0, str.length)];
    
    NSMutableParagraphStyle *style = [[NSMutableParagraphStyle alloc] init];
    style.alignment = NSTextAlignmentCenter;
    [loginNamePlace_attributedString addAttributes:@{NSParagraphStyleAttributeName:style} range:NSMakeRange(0, str.length)];
    return loginNamePlace_attributedString;
}
@end
